package com.ruibang.glass.produce.component.job;

import com.ruibang.glass.produce.entity.DefectDepthAnalysis;
import com.ruibang.glass.produce.mapper.DefectDepthAnalysisMapper;
import com.teaming.cloud.framework2.elastic.job3.annotation.ElasticJobScheduler;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Author: songJinKang
 * @CreateTime: 2024-04-27  17:32
 * @Description: TODO
 * @Version: 1.0
 */

@Slf4j
@ElasticJobScheduler(cron = "6 11 0/1 * * ?")
//@ElasticJobScheduler(cron = "0 * * * * ?")
@Component
public class DefectDepthAnalysisTask implements SimpleJob {

    @Autowired
    private DefectDepthAnalysisMapper defectDepthAnalysisMapper;

    @Override
    public void execute(ShardingContext shardingContext) {
        LocalDateTime currentTime = LocalDateTime.now();
        LocalDateTime cTime = currentTime.minusHours(1);
        LocalDateTime startTime = LocalDateTime.of(cTime.getYear(), cTime.getMonthValue(), cTime.getDayOfMonth(), cTime.getHour(), 0, 0);
        LocalDateTime endTime = LocalDateTime.of(currentTime.getYear(), currentTime.getMonthValue(), currentTime.getDayOfMonth(), currentTime.getHour(), 0, 0);

        //获取数据
        DefectDepthAnalysis defectDepthAnalysis = defectDepthAnalysisMapper.getLastHourData(startTime, endTime);
        defectDepthAnalysis.setCollectTime(startTime);
        defectDepthAnalysisMapper.insert(defectDepthAnalysis);
    }


}




